package com.itheima.edu.info.manager.factory;

import com.itheima.edu.info.manager.dao.BaseStudentDao;
import com.itheima.edu.info.manager.dao.OtherStudentDao;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.ResourceBundle;

//注意：当方法的返回值类型是一个接口类型时，方法中需要返回的时该接口的实现类对象

public class StudentFactory {
    /*
学生库管工厂类
    专门对外提供学生库管对象

     */
    public static BaseStudentDao getStudentDao() {

        //功能优化：基于反射+配置文件方式解开耦合
        try {


           ResourceBundle bundle = ResourceBundle.getBundle("prop");
         //   System.out.println(bundle.getString("studentDaoName"));
            //反射创建类对象
            Class clazz = Class.forName(bundle.getString("studentDaoName"));
            return (BaseStudentDao) clazz.newInstance();


        } catch (Exception e) {
            System.out.println("学生工厂发生异常");
        }


        return null;
        // return new OtherStudentDao();

    }
}
